# @Version        : 1.0
# @Update Time    : 2025/3/24 22:42
# @File           : track_utils.py
# @IDE            : PyCharm
# @Desc           : 链路追踪上下文管理器
import uuid
from .request_context import REQUEST_ID_MANAGER


# 链路追踪上下文工具类
class TrackContextUtils:
    # 设置请求唯一id
    @staticmethod
    def set_request_id(req_id: str = None, title="req-id") -> str:
        req_id = req_id or uuid.uuid4().hex
        req_id = f"{title}:{req_id}"
        REQUEST_ID_MANAGER.set(req_id)
        return req_id

    # 获取请求唯一id
    @staticmethod
    def get_request_id() -> str:
        return REQUEST_ID_MANAGER.get()
